package com.bdqn.sj.service;

import com.bdqn.sj.User;
import com.bdqn.sj.dao.UserDao;
import com.bdqn.sj.dao.UserDaoImpl;
import com.bdqn.sj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 用户模块业务层实现
 */
@Service("userService")
public class UserServiceImpl implements UserService {
    /**
     * 声明接口类型的引用，和具体实现类解耦合
     */
//    @Autowired
//    @Qualifier("userDao")
    @Resource(name = "userDao")
    private UserDao userDao;


    //用于为dao属性赋值的构造方法
    public UserServiceImpl(UserDao userDao) {
        this.userDao = userDao;
    }

    /**
     * 保存用户信息
     *
     * @param user
     */
    @Override
    public void save(User user) {
        //调用UserDao的方法保存用户信息
        userDao.save(user);
    }


    /**
     * dao属性的setter访问器，会被Spring调用，实现依赖注入
     *
     * @param userDao
     */
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }
}
